<?php

use yii\db\Schema;
use yii\db\Migration;

class m150211_073923_add_retargeting_tables extends Migration
{
    public function up()
    {
		$sql =<<<FINE
DROP TABLE IF EXISTS {{%condition_redirect}};
DROP TABLE IF EXISTS {{%condition_retarget}};
CREATE TABLE {{%condition_retarget}} (
  id int(11) unsigned NOT NULL AUTO_INCREMENT,
  solution_id int(11) unsigned NOT NULL,
  is_whitelist int(1) NOT NULL DEFAULT 0 COMMENT '0 blacklist, 1 whitelist, of no use for this condition',
  retarget_type_id int(11) COMMENT '重定向类型 id',
  tag varchar(1024) COMMENT '重定向标签',
  status int(1) NOT NULL DEFAULT 1 COMMENT '1 有效， 0 无效（删除或其他情况）',
  last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS {{%retarget_type}};
CREATE TABLE {{%retarget_type}} (
  id int(11) unsigned NOT NULL AUTO_INCREMENT,
  name varchar(64) DEFAULT NULL COMMENT '重定向类型名称',
  status int(1) NOT NULL DEFAULT 1 COMMENT '1 有效， 0 无效（删除或其他情况）',
  last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO {{%retarget_type}}(name) values('品牌重定向');

FINE;
	
		$this->execute($sql);	
    }

    public function down()
    {
		$this->dropTable('{{%condition_retarget}}');
		$this->dropTable('{{%retarget_type}}');
    }
}
